<?php
/**
 * Created by PhpStorm.
 * User: yyq
 * Date: 2018/2/6
 * Time: 17:07
 */

namespace System\Controller;


use Common\Controller\AdminbaseController;
use Common\Model\AppConfigModel;

class AppConfigController extends AdminbaseController
{
    private $app_config_model;

    public function __construct()
    {
        parent::__construct();
        $this->app_config_model = new AppConfigModel();
    }

    /**
     * 配置信息
     */
    public function edit() {
        if(IS_POST) {
//            dump($_POST);exit;
            foreach ($_POST as $k => &$v) {
//                dump($v);
                if(is_array($v)) {
                    $v = json_encode($v);
                }

                $rst_2 = $this->app_config_model->where(['option_name' => $k])->save(['option_value' => $v]);
                /*if(!$rst_2) {
                    $this->error('请重试'.$k);
                }*/
            }
            unset($v);
            $this->success('成功');
        } else {
            $result = $this->app_config_model->select();
            $data = [];
            foreach ($result as $k => $v) {
//                dump(json_decode($v['option_value'], true));

                $data[$v['option_name']] = $v['option_value'];
//                $data[$v['option_name']] = json_decode($v['option_value'], true);
            }
            $this->assign($data);
            $this->display();
        }
    }


}